package com.fengxing.ams.web.facade;

import java.util.Date;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.fengxing.ams.web.facade.intf.IAccountFacade;
import com.fengxing.ams.web.facade.mouble.user.IMenuDao;
import com.fengxing.ams.web.facade.mouble.user.IRoleDAO;
import com.fengxing.ams.web.facade.mouble.user.IUserDAO;
import com.fengxing.ams.web.facade.mouble.user.UserVO;
import com.fengxing.ams.web.security.utils.PasswordUtil;

/**
 * 用户管理业务类.
 * 
 * @author XILIU
 *
 */
@Component
@Transactional
public class AccountFacade extends BaseFacade implements IAccountFacade {
	private static Logger logger = LoggerFactory.getLogger(AccountFacade.class);
	
	@Autowired
	private IUserDAO userDAO;
	@Autowired
	private IRoleDAO roleDao;
	@Autowired
	private IMenuDao menuDao;
	
	/**
	 * 按登录名查询用户.
	 */
	@Override
	public UserVO findUserByEmail(String email) {
		return userDAO.findByEmail(email);
	}
	
	@Transactional(readOnly = false)
	public void updateUserLoginInfo(Long id) {
		userDAO.updateLoginInfo(id, SecurityUtils.getSubject().getSession().getHost(), new Date());
	}
	
	@Transactional(readOnly = false)
	public void updatePasswordById(Long id, String loginName, String newPassword) {
		userDAO.updatePasswordById(id, PasswordUtil.entryptPassword(newPassword));
	}
}
